<script>

let arr = [9,3,23,41,5,3,4,436,4,523,52,234,5,324,51,3,4,6,12,52]
function mergeSort(arr){
    if(arr.length < 2){
        return arr
    }
    let mid = Math.floor(arr.length / 2)
    let left = arr.slice(0, mid)
    let right = arr.slice(mid)
    return merge(mergeSort(left), mergeSort(right))
}

//对元素排序
function merge(left, right){
    let arr = []
    while(left.length && right.length){
        if(left[0] > right[0]){
            arr.push(right.shift())
        }else{
            arr.push(left.shift())
        }
    }
    return arr.concat(left, right)
}
console.log(mergeSort(arr))
</script>